<template>
  <div class="applyCash">
    <div class="applyCash_account">
        <p class="account_num">到账账户：{{account_num}}</p>
        <p class="edit" @click="clickEdit('certification')">修改</p>
    </div>
    <div class="applyCash_main">
        <div class="applyCash_main_box">
          <h6>提现金额</h6>
          <div class="enter_amount">
          <span>￥</span>
          <input type="text" placeholder="请输入提现金额" v-model="account" />
          </div>
          <p class="tip">本次提现扣除的手续费为 <span>{{poundage}}元</span> ({{account||'0.00'}}元 x {{withdraw_proportion}}%)</p>
        </div>
        <div class="applyCash_btn" @click="clickCertification">申请提现</div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { editEnterpriseAudit, getBalanceDraw } from '@/api/user/member/memberApi'
import { doTX } from '@/api/user/fxs/fxsApi'
import { doSupplierWithdraw } from '@/api/user/gys/gysApi'
export default Vue.extend({
  components: {},
  props: {},
  data() {
    return {
      enterprise_id: '', // 企业id
      account_num: '', // 到账账户
      account: '', // 充值金额
      withdraw_proportion: '', // 手续费比例
      routeQuery: {
        withdraw_type: '', // 提现类型
        code: ''
      }
    }
  },
  created() {
    this.routeQuery.withdraw_type = this.$route.query.withdrawType
    this.routeQuery.code = this.$route.query.code
  },
  mounted() {
    this.$nextTick(() => {
      this.getEnterpriseAccount()
    })
  },
  methods: {
    // 获取企业信息
    getEnterpriseAccount() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)
      editEnterpriseAudit().then(res => {
        this.$loadingWrap.close()
        const enterpriseInfo = res.data.enterprise_info
        if (res.status == 1) {
          this.enterprise_id = enterpriseInfo.enterprise_id
          this.account_num = enterpriseInfo.enterprise_account
          if (this.routeQuery.withdraw_type == 'balanceTx') {
            this.withdraw_proportion = enterpriseInfo.enterprise_balance_ratio
          } else if (this.routeQuery.withdraw_type == 'myCommission') {
            this.withdraw_proportion = enterpriseInfo.enterprise_commission_ratio
          } else if (this.routeQuery.withdraw_type == 'supplierWithdraw') {
            this.withdraw_proportion = enterpriseInfo.enterprise_gys_balance_ratio
          }
        } else {
          this.$Error(res.msg)
        }
      })
    },
    // 修改企业信息
    clickEdit(url, data) {
      this.$JumpPath(this, url, data)
    },
    // 申请提现
    clickCertification() {
      if (this.account <= 0) {
        this.$Error('输入金额不能小于0！')
        return false
      }
      const sendData = {
        source: 'enterprise',
        type: 3,
        alipay_account: this.account_num,
        code: this.routeQuery.code,
        money: this.account
      }
      if (this.routeQuery.withdraw_type == 'balanceTx') {
        this.$loadingWrap.show()
        setTimeout(() => {
          this.$loadingWrap.close()
        }, 10000)
        getBalanceDraw(sendData).then(res => {
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.$Error(res.data.msg)
            // 获取当前时间
            var myDate = new Date()
            var totalSeconds = Math.round(myDate.getTime() / 1000)
            setTimeout(() => {
              this.$JumpPath(this, 'balanceTx', '')
            }, 1000)
            Storage.saveLocal('time_status', totalSeconds)
          } else {
            this.$Error(res.msg)
          }
        })
      } else if (this.routeQuery.withdraw_type == 'myCommission') {
        this.$loadingWrap.show()
        setTimeout(() => {
          this.$loadingWrap.close()
        }, 10000)
        doTX(sendData).then(res => {
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.$Error(res.data.msg)
            // 获取当前时间
            var myDate = new Date()
            var totalSeconds = Math.round(myDate.getTime() / 1000)
            setTimeout(() => {
              this.$JumpPath(this, 'myCommission', '')
            }, 1000)
            Storage.saveLocal('time_status', totalSeconds)
          } else {
            this.$Error(res.msg.msg || res.msg)
          }
        })
      } else if (this.routeQuery.withdraw_type == 'supplierWithdraw') {
        this.$loadingWrap.show()
        setTimeout(() => {
          this.$loadingWrap.close()
        }, 10000)
        doSupplierWithdraw(sendData).then(res => {
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.$Error(res.msg)
            // 获取当前时间
            var myDate = new Date()
            var totalSeconds = Math.round(myDate.getTime() / 1000)
            setTimeout(() => {
              this.$JumpPath(this, 'supplierWithdraw', '')
            }, 1000)
            Storage.saveLocal('time_status', totalSeconds)
          } else {
            this.$Error(res.msg)
          }
        })
      }
    }
  },
  computed: {
    poundage() { // 计算手续费
      let num = this.account * (this.withdraw_proportion / 100)
      num = num || 0
      return num.toFixed(2)
    }
  },
  watch: {
  }
})
</script>

<style lang="scss">
.applyCash{
    &_account{
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 28px;
        width: 100%;
        height: 96px;
        line-height: 96px;
        padding: 0 30px;
        margin-bottom: 30px;
        background-color: #fff;
        border-radius: 0px 0px 20px 20px;
        .edit{
            color: #F11228;
        }
    }
    &_main{
        width: 100%;
        padding: 0 25px;
        .name_tip{
          font-size: 24px;
          line-height: 44px;
          color: #999;
        }
        &_box{
            width: 100%;
            padding: 40px 30px;
            background-color: #fff;
            border-radius: 20px;
            >h6{
                font-size: 32px;
                color: #333;
                margin-bottom: 25px;
            }
            .enter_amount{
                padding: 32px 0;
                margin-bottom: 22px;
                border-bottom: 1px solid #ededed;
                >span{
                    font-weight: bold;
                    font-size: 40px;
                    color:#333;
                }
                input{
                    font-size: 38px;
                }
            }
            .tip{
                font-size: 26px;
                color: #666;
                span{
                    color: #F11227;
                }
            }
        }
        .applyCash_btn{
            font-size: 32px;
            color: #fff;
            width: 100%;
            height: 92px;
            line-height: 92px;
            text-align: center;
            margin: 40px 0;
            background: linear-gradient(to right,#FD1B49, #E90103);
            border-radius: 46px;
        }
        .applyCash_tip{
            .tip_title{
                display: flex;
                align-items: center;
                font-size: 28px;
                color: #333;
                margin-bottom: 24px;
                >img{
                    width: 32px;
                    height: 32px;
                    margin-right: 8px;
                }
            }
            .tip_content{
                font-size: 26px;
                color: #666;
            }
        }
    }
}
</style>